package com.java.simple.sort;

import java.util.Arrays;

/**
 * @author zhoujunlin
 * @date 2022年08月09日 11:34
 * @desc 插入排序
 * 时间复杂度 n^2
 * https://blog.csdn.net/qq_41219157/article/details/123359072
 */
public class InsertionSort {

    public static void main(String[] args) {
        int[] numArr = new int[]{1, 10, 2, 8, 3, 4, 7, 6, 5, 9};
        insertionSort(numArr);
        System.out.println(Arrays.toString(numArr));
    }


    private static void insertionSort(int[] numArr) {
        for (int i = 0; i < numArr.length - 1; i++) {
            for (int j = i + 1; j > 0; j--) {
                if (numArr[j] < numArr[j - 1]) {
                    SwapUtil.swap(numArr, j, j - 1);
                } else {
                    break;
                }
            }
        }
    }

}
